//2009/08/18 10:00:19
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class TriFibonacci
{
public:
    int complete(vector <int> a)
    {
		int ret = -1;
		for(int i=0; i<a.size(); i++)
		{
			if(a[i] == -1)
			{
				if(i<3) 
				{
					int temp = a[0] + a[1] + a[2];
						ret = a[3] - temp -1;
				}
				else ret = a[i-1] + a[i-2] + a[i-3];
				a[i] = ret;
			}
		}
		
		for(int i=3; i<a.size(); i++)
		{
			if(a[i-3] <= 0 ||a[i-2] <= 0 ||a[i-1] <= 0 ||a[i] <= 0 || a[i] != a[i-1] + a[i-2] + a[i-3]) return -1;
		}
		return ret;
    }
};
